package edu.pku.sei.transformation.qvt.adapter.standardqvt;

import edu.pku.sei.transformation.editor.model.GraphicalDomain;
import edu.pku.sei.transformation.editor.views.problem.ProblemView;
import edu.pku.sei.transformation.qvt.rule.IDomain;
import edu.pku.sei.transformation.qvt.rule.IObjectTemplate;
import edu.pku.sei.transformation.qvt.rule.IPattern;

public class DomainAdapter implements IDomain {
	protected GraphicalDomain element;
	protected IPattern pattern;

	public DomainAdapter(GraphicalDomain element) {
		this.element = element;
		addPattern();
	}
	
	protected void addPattern() {
		pattern = new PatternAdapter(element.getPattern());		
	}

	@Override
	public IPattern getPattern() {
		return pattern;
	}

	@Override
	public IObjectTemplate getRootElement() {
		if (pattern.getNodes().size() == 0)
			ProblemView.addError(element.getModel(), ProblemView.CODEGEN_QVT, "domain root", "no element in domain", element.getContainer().toString());
		return pattern.getNodes().get(0);
	}

	@Override
	public String getTypedModelName() {
		if (element.getTypedModel() == null)
			return "";
		else
			return element.getTypedModel().getName();
	}

	@Override
	public boolean isEnforce() {
		return element.isEnforceable();
	}

}
